﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PackageManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PackageManagement.PackageBankVMs
{
    public partial class PackageBankListVM : BasePagedListVM<PackageBank_View, PackageBankSearcher>
    {
        
        protected override IEnumerable<IGridColumn<PackageBank_View>> InitGridHeader()
        {
            return new List<GridColumn<PackageBank_View>>{
                
                this.MakeGridHeader(x => x.PackageBank_Sn).SetTitle(@Localizer["Page.装箱条码"].Value),
                this.MakeGridHeader(x => x.PackageBank_WoId).SetTitle(@Localizer["Page.工单"].Value),
                this.MakeGridHeader(x => x.PackageBank_WoCode).SetTitle(@Localizer["Page.工单编码"].Value),
                this.MakeGridHeader(x => x.PackageBank_ProductId).SetTitle(@Localizer["Page.装箱产品"].Value),
                this.MakeGridHeader(x => x.PackageBank_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.PackageBank_StartTime).SetTitle(@Localizer["Page.首次装箱时间"].Value),
                this.MakeGridHeader(x => x.PackageBank_LastTime).SetTitle(@Localizer["Page.最后装箱时间"].Value),
                this.MakeGridHeader(x => x.PackageBank_LastSn).SetTitle(@Localizer["Page.最后零件条码"].Value),
                this.MakeGridHeader(x => x.PackageBank_CurrentCount).SetTitle(@Localizer["Page.当前装箱数量"].Value),
                this.MakeGridHeader(x => x.PackageBank_Qty).SetTitle(@Localizer["Page.可装数量"].Value),
                this.MakeGridHeader(x => x.PackageBank_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<PackageBank_View> GetSearchQuery()
        {
            var query = DC.Set<PackageBank>()
                
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.WoId, x=>x.WoId)
                .CheckContain(Searcher.WoCode, x=>x.WoCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckContain(Searcher.LastTime, x=>x.LastTime)
                .CheckContain(Searcher.LastSn, x=>x.LastSn)
                .CheckEqual(Searcher.CurrentCount, x=>x.CurrentCount)
                .CheckEqual(Searcher.Qty, x=>x.Qty)
                .Select(x => new PackageBank_View
                {
				    ID = x.ID,
                    
                    PackageBank_Sn = x.Sn,
                    PackageBank_WoId = x.WoId,
                    PackageBank_WoCode = x.WoCode,
                    PackageBank_ProductId = x.ProductId,
                    PackageBank_ProductName = x.ProductName,
                    PackageBank_StartTime = x.StartTime,
                    PackageBank_LastTime = x.LastTime,
                    PackageBank_LastSn = x.LastSn,
                    PackageBank_CurrentCount = x.CurrentCount,
                    PackageBank_Qty = x.Qty,
                    PackageBank_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class PackageBank_View: PackageBank
    {
        
        public string PackageBank_Sn { get; set; }
        public long? PackageBank_WoId { get; set; }
        public string PackageBank_WoCode { get; set; }
        public long? PackageBank_ProductId { get; set; }
        public string PackageBank_ProductName { get; set; }
        public DateTime? PackageBank_StartTime { get; set; }
        public string PackageBank_LastTime { get; set; }
        public string PackageBank_LastSn { get; set; }
        public decimal? PackageBank_CurrentCount { get; set; }
        public decimal? PackageBank_Qty { get; set; }
        public bool PackageBank_IsValid { get; set; }

    }

}